package com.crm.crm.controller;

import com.crm.crm.domain.SysNotice;
import com.crm.crm.domain.vo.PageResult;
import com.crm.crm.domain.vo.business.result.Result;
import com.crm.crm.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    /**
     * 消息列表
     *
     * @param status
     * @return
     */
    @GetMapping("/pagelist/{status}")
    public Result pageList(@PathVariable Integer status) {
        PageResult<SysNotice> pageResult = noticeService.pageList(status);
        return Result.success().put("total", pageResult.getTotal()).put("rows", pageResult.getRows());
    }

    /**
     * 读取操作
     *
     * @param noticeId
     * @return
     */
    @PutMapping("/{noticeId}")
    public Result update(@PathVariable Long noticeId) {
        return noticeService.update(noticeId) ? Result.success() : Result.error();
    }

    /**
     * 获取消息列表
     *
     * @param id
     * @return
     */
    @GetMapping("/list/{id}")
    public Result getNoticeList(Integer id) {
        List<SysNotice> list = noticeService.selectList(id);
        return Result.success(list);
    }

}
